/*
 * @(#)CheckService.java $version 2013. 9. 3.
 *
 */

package com.pace.gonu.api;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.pace.gonu.model.chnl.PlayChannel;
import com.pace.gonu.model.status.PlayStatus;
import com.pace.gonu.play.PlayService;

/**
 * @author pace
 */
@Service
public class CheckService {
	@Autowired
	private PlayService playService;

	public boolean check(int chnlnumber) {
		PlayChannel playChannel = playService.getChannel(chnlnumber);
		//		playChannel.setLastAccessDate(Calendar.getInstance());
		if (playChannel.isPlay()) {
			return true;
		}
		return false;
	}

	public String playCheck(int chnlnumber, String orderStr) {
		PlayChannel playChannel = playService.getChannel(chnlnumber);
		PlayStatus playStatus = playChannel.getPlayStatusObject();
		//		playChannel.setLastAccessDate(Calendar.getInstance());
		if (playChannel.getWinner() != null) {
			return "end";
		} else if (StringUtils.equals(orderStr, playStatus.getOrder())) {
			return "ok";
		}
		return "fail";
	}
}
